/*
 * This file is part of SimpLie.
 * 
 * SimpLie is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * SimpLie is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with SimpLie.  If not, see <http://www.gnu.org/licenses/>.
 */
 
/*
 * RepSpinner.java
 *
 * Created on 4-jun-2009, 12:36:18
 */

package edu.simplie.ui.reps;

import edu.simplie.algebra.*;

/**
 *
 * @author Teake Nutma
 * @version $Revision: 446 $, $Date: 2014-09-27 19:02:43 +0000 (Sat, 27 Sep 2014) $
 */
public class RepSpinner extends javax.swing.JPanel
{
	private Algebra algebra;
	private HighestWeightRep HWrep;

    /** Creates new form RepSpinner */
    public RepSpinner()
	{
        initComponents();
		HWspinner.setMinValue(0);
		algebra		= null;
		HWrep		= null;
    }

	public void setAlgebra(Algebra algebra)
	{
		this.algebra = algebra;
		HWspinner.setNumSpinners(algebra.rank);
		repChanged();
	}

	public HighestWeightRep getRepresentation()
	{
		return HWrep;
	}

	public void reset()
	{
		HWspinner.setValue(0);
	}

	private void repChanged()
	{
		int[] labels = HWspinner.getValues();
		if(algebra != null && algebra.rank > 0 && labels.length == algebra.rank)
		{
			HWrep = new HighestWeightRep(algebra,labels);
			tfDim.setText(HWrep.dimension);
		}
	}

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        HWspinner = new edu.simplie.ui.reusable.UIMultiSpinner();
        tfDim = new javax.swing.JLabel();

        setName("Form"); // NOI18N

        HWspinner.setName("HWspinner"); // NOI18N
        HWspinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                repChanged(evt);
            }
        });

        tfDim.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        tfDim.setText(" "); // NOI18N
        tfDim.setName("tfDim"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(HWspinner, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(tfDim))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tfDim, javax.swing.GroupLayout.DEFAULT_SIZE, 28, Short.MAX_VALUE)
            .addComponent(HWspinner, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

	private void repChanged(javax.swing.event.ChangeEvent evt)//GEN-FIRST:event_repChanged
	{//GEN-HEADEREND:event_repChanged
		repChanged();
	}//GEN-LAST:event_repChanged


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private edu.simplie.ui.reusable.UIMultiSpinner HWspinner;
    private javax.swing.JLabel tfDim;
    // End of variables declaration//GEN-END:variables

}
